package com.sdy.service.Impl;

import com.sdy.dao.mysql.OrderItemMapper;
import com.sdy.dao.mysql.ProductMapper;
import com.sdy.po.OrderItem;
import com.sdy.po.Product;
import com.sdy.po.Specification;
import com.sdy.service.OrderItemSercive;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderItemServiceImpl implements OrderItemSercive {

    @Resource
    OrderItemMapper orderItemMapper;
    @Resource
    ProductMapper productMapper;

    @Override
    public List<OrderItem> getAll() {
        return null;
    }

    @Override
    public OrderItem getOne() {
        return null;
    }

    @Override
    public Boolean update(OrderItem orderItem) {
        return null;
    }

    @Override
    public Boolean insert(OrderItem orderItem) {
        return null;
    }

    @Override
    public Boolean delete(Integer id) {
        return null;
    }

    /**
     * 根据订单id查询订单中的商品
     * @param id
     * @return
     */
    @Override
    public List<OrderItem> getListByOrderId(Integer id) {
        List<OrderItem> orderItemList = orderItemMapper.getListByOrderId(id);
        for (OrderItem orserItem:orderItemList) {
            Product product = orserItem.getProduct();
            for (Specification specification:product.getSpecificationList()) {
                if (specification.getId() == orserItem.getSpecificationId()){
                    product.setSpecification(specification);
                    break;
                }
            }
        }
        return orderItemList;
    }
}
